
#ifndef	LEVEL_SLIDE_OBJECT_DYNAMIC_HPP
#define	LEVEL_SLIDE_OBJECT_DYNAMIC_HPP

#include <level/slide/object/object.hpp>
#include <rapidxml/rapidxml.hpp>

class dynamic_object : public object
{
public:

	dynamic_object( rapidxml::xml_node<>* node, world_ptr world )
	{
		load_animation( node );

		b2BodyDef definition;
		definition.type = b2_dynamicBody;
		definition.position = g_inv_scale_b2_position * read_from_node<b2Vec2>( node->first_node( "position" ), definition.position );
		definition.angle = read_from_node<float32>( node->first_node( "angle" ), definition.angle );
		definition.linearDamping = read_from_node<float32>( node->first_node( "dampening" ), definition.linearDamping );
		definition.angularDamping = read_from_node<float32>( node->first_node( "angular_dampening" ), definition.angularDamping );
		definition.fixedRotation = read_from_node<bool>( node->first_node( "fixed_rotation" ), definition.fixedRotation );
		definition.allowSleep = true;

		m_body = create_body( world, &definition );
		assign_user_data( );

		if ( rapidxml::xml_node<> * shapes = node->first_node( "shapes" ) )
		{
			for (	rapidxml::xml_node<>* shape = shapes->first_node( "shape" );
					shape != nullptr;
					shape = shape->next_sibling( shape->name( ) ) )
			{
				add_shape( shape );
			}
		}
	}
};

#endif	//LEVEL_SLIDE_OBJECT_DYNAMIC_HPP
